package com.origin.app.bean;

import android.util.Log;

import com.origin.utils.log.LogUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class CompanyBean {


    /**
     * id : 353
     * company_name : 七组
     * company_code : 007
     * level : 4
     * parent_id : 344
     * system_id : 2
     * sort_id : 0
     */

    private String tag="";
    private int id;
    private String company_name;
    private String company_code;
    private int level;
    private int parent_id;
    private int system_id;
    private int sort_id;

    private int nextSize=0;

    private boolean isOpen=true;

    private  boolean isSelect=true;

    //     var companyBeanList = mutableListOf<CompanyBean>();

    // 下一级的集合
    private  List<CompanyBean> companyBeanList = new ArrayList<>();

    public List<CompanyBean> getCompanyBeanList() {
        return companyBeanList;
    }

    public void addCompanyBean(CompanyBean companyBean) {
        this.companyBeanList .add(companyBean) ;
    }

    public boolean isSelect() {
        return isSelect;
    }

    public void setSelect(boolean select) {
        isSelect = select;
    }

    public boolean isOpen() {
        return isOpen;
    }

    public void setOpen(boolean open) {
        isOpen = open;
    }

    public int getNextSize() {
        return nextSize;
    }

    public void setNextSize(int nextSize) {
        this.nextSize = nextSize;
    }

    public String getTag() {
        return tag;
    }

    public void setTag(String tag) {
        this.tag = tag;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getCompany_name() {
        return company_name;
    }

    public void setCompany_name(String company_name) {
        this.company_name = company_name;
    }

    public String getCompany_code() {
        return company_code;
    }

    public void setCompany_code(String company_code) {
        this.company_code = company_code;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public int getParent_id() {
        return parent_id;
    }

    public void setParent_id(int parent_id) {
        this.parent_id = parent_id;
    }

    public int getSystem_id() {
        return system_id;
    }

    public void setSystem_id(int system_id) {
        this.system_id = system_id;
    }

    public int getSort_id() {
        return sort_id;
    }

    public void setSort_id(int sort_id) {
        this.sort_id = sort_id;
    }

    @Override
    public String toString() {
        return "CompanyBean{" +
                "id=" + id +
                ", company_name='" + company_name + '\'' +
                ", company_code='" + company_code + '\'' +
                ", level=" + level +
                ", parent_id=" + parent_id +
                ", system_id=" + system_id +
                ", sort_id=" + sort_id +
                '}';
    }


    public  boolean isParentLevel(List<Integer> ids){
        if(tag==null||tag.equals("")){
            return  false;
        };
        List<Integer> tags = new ArrayList<>();
        String[] parts = tag.split(",");
        for (String part : parts) {
            if (!part.isEmpty()) {
                tags.add(Integer.parseInt(part.trim()));
            }
        }
        Set<Integer> set = new HashSet<>(ids);

        boolean hasCommonElements = false;

        for (Integer element : tags) {
            if (set.contains(element)) {
                hasCommonElements = true;
                break;
            }
        }
        return  hasCommonElements;
    }

    public String getInfo(){
//        return  tag +" 下一级长度: "+nextSize +" id: " +id+ " level: " +level + " Parent_id: " +getParent_id() + "  name: "+company_name;
        return  company_name;
    }

}
